$(function () {
   const height = $('.nav-search-box').height()
    $('.input-search').addClass('hide')
    $('.nav-search-box').css({
        height: 0
    })
    $('.search-box').on('click', function () {
        $(this).find('a .fang-djing').hide()
        $('.input-search').show().find('.nav-search-box').show().animate({
                height
            },
            100)
        $('.nav-search-input').focus()
    })
    $('.nav-search-input').on('blur', function () {
        $('.nav-search-box').css({
            height: 0
        })
        $('.input-search').hide()
        $('.fang-djing').show()
    })

    $('#personal-center').mouseenter(function () {
        $('#header-avator img').addClass('red')
        $('.g-user-card').show()
    })
    $('#personal-center').mouseleave(function () {
        $('#header-avator img').removeClass('red')
        $('.g-user-card').hide()
    })
    $('.cfg').click(function () {
        $(this).hide()
        $('.cfvg1').show()
        $('.uit-int').css('height', '196px')
        $('.fycg').show()
    })
    $('.cfvg1').on('click', function () {
        $(this).hide()
        $('.cfg').show()
        $('.uit-int').css('height', '148px')
        $('.fycg').hide()
    })
    $(window).scroll(function () {
        var top = $('html,body').scrollTop()
        if (top >= 220) {
            $('.thl-rat').css('position', 'fixed')
            $('.thl-rat').css('left', '97px')
            $('.thl-rat').css('top', '60px')
        } else {
            $('.thl-rat').css('position', 'absolute')
            $('.thl-rat').css('left', '24px')
            $('.thl-rat').css('top', '0')
        }
    })
    $('.alwj').on('click', function () {
        $(this).addClass('afsd')
        $(this).siblings().removeClass('afsd')
    })
    $('.thl-rat>ul>li').on('click', function () {
        $(this).children().addClass('aipo').children('.i').addClass('icon-dengbiansanjiaoxin')
        $(this).siblings().children().removeClass('aipo').children('.i').removeClass('icon-dengbiansanjiaoxin')
    })


    // 数据渲染
    $.get('/my/userinfo').then(res => {
        if (res.status == 1 && res.message === 'token失效或错误') {
            location.href = '/login.html'
            return layer.msg('token失效或错误')
        }
        const {
            nickname,
            avatar,
            sex,
            region,
            position,
            profile
        } = res.data
        console.log(res)
        if (nickname) {
            $('.name').text(nickname)
        }
        if (avatar.startsWith('/upload')) {
            $('.xgtp, .avator').attr('src', 'http://127.0.0.1:3000' + avatar)
        } else {
            $('.xgtp, .avatar').attr('src', avatar)
        }
        if(sex){
            $('.sex').text(sex)
        }
        if(region !== '请选择' || region !== '' || region !== null){
            $('.region').text(region)
        }
        if(position){
            $('.position').text(position)
        }
        if(profile){
            $('.htyu').text(profile)
        }
    })
})